﻿//=============================地区调用方法 begin======================================

//选择省份Kid获取城市数据
function selectProvinceKid(F_ProvinceKid) {
    $("#F_CityKid").empty();
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "/SysManager/GetJsonProvinceCityAreaByKid/",
        data: { Kid: F_ProvinceKid },
        success: function (result) {
            $.msgAlert(result, function (jsobj) {
                $.each(jsobj.Data, function (key, data) {
                    $("#F_CityKid").append("<option value=" + data.Kid + ">" + data.F_Name + "</option>");
                });
            });
        }
    });
}
//选择省份Kid获取城市数据
function selectProvinceKid_ByAdminKid(F_ProvinceKid) {
    $("#F_CityKid").empty();
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "/SysManager/GetJsonProvinceCityAreaByKid_ByAdminKid/",
        data: { Kid: F_ProvinceKid },
        success: function (result) {
            $.msgAlert(result, function (jsobj) {
                $.each(jsobj.Data, function (key, data) {
                    $("#F_CityKid").append("<option value=" + data.Kid + ">" + data.F_Name + "</option>");
                });
            });
        }
    });
}
//选择城市Kid获取区县数据
function selectCityKid(F_CityKid) {
    $("#F_AreaKid").empty();
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "/SysManager/GetJsonProvinceCityAreaByKid/",
        data: { Kid: F_CityKid },
        success: function (result) {
            $.msgAlert(result, function (jsobj) {
                $.each(jsobj.Data, function (key, data) {
                    $("#F_AreaKid").append("<option value=" + data.Kid + ">" + data.F_Name + "</option>");
                });
            });
        }
    });
}
//选择城市Kid获取区县数据
function selectAreaKid(F_AreaKid) {
    $("#F_PlateKid").empty();
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "/SysManager/GetJsonProvinceCityAreaByKid/",
        data: { Kid: F_AreaKid },
        success: function (result) {
            $.msgAlert(result, function (jsobj) {
                $.each(jsobj.Data, function (key, data) {
                    $("#F_PlateKid").append("<option value=" + data.Kid + ">" + data.F_Name + "</option>");
                })
            });
        }
    });
}

//=============================地区调用方法 end========================================


//=============================数组扩展方法 begin======================================

Array.prototype.del = function (index) {
    if (isNaN(index) || index >= this.length) {
        return false;
    }
    for (var k = 0, n = 0; k < this.length; k++) {
        if (this[k] != this[index]) {
            this[n++] = this[k];
        }
    }
    this.length -= 1;
};

//=============================数组扩展方法 end========================================


//=============================日期扩展方法 begin======================================

Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
	(this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
		RegExp.$1.length == 1 ? o[k] :
		("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

//=============================日期扩展方法 end========================================

//=============================渲染 radio，checkbox 扩展方法 begin======================================
function initInput() {
    $('.lab112 :radio').iCheck({
        checkboxClass: 'icheckbox_minimal-orange',
        radioClass: 'iradio_minimal-orange',
        increaseArea: '20%' // optional
    });

    $('.lab112 :checkbox').iCheck({
        checkboxClass: 'icheckbox_minimal-orange',
        radioClass: 'iradio_minimal-orange',
        increaseArea: '20%' // optional
    });
}

//=============================渲染 radio，checkbox 扩展方法 end========================================



//=============================加减乘除 begin=================================

//重写 toFixed()
Number.prototype.toFixed = function (exponent) {
    return parseInt(this * Math.pow(10, exponent) + 0.5) / Math.pow(10, exponent);
}


function yunshuan(a, how, b) {//正确浮点运算   
    if (a.toString().indexOf(".") < 0 && b.toString().indexOf(".") < 0) {//没小数   
        return eval(a + how + b);
    }
    //至少一个有小数   
    var alen = a.toString().split(".");
    if (alen.length == 1) {//没有小数   
        alen = 0;
    } else {
        alen = alen[1].length;
    }
    var blen = b.toString().split(".");
    if (blen.length == 1) {
        blen = 0;
    } else {
        blen = blen[1].length;
    }
    if (blen > alen) alen = blen;
    blen = "1";
    for (; alen > 0; alen--) {//创建一个相应的倍数   
        blen = blen + "0";
    }
    switch (how) {
        case "+":
            return (a * blen + b * blen) / blen;
            break;
        case "-":
            return (a * blen - b * blen) / blen;
            break;
        case "*":
            return ((a * blen) * (b * blen)) / (blen * blen);
            break;
        case "/":
            return ((a * blen) / (b * blen)) / (blen * blen);
            break;
        default:
            alert("你要求的\t" + how + "\t运算未完成!");
            return eval(a + how + b);
    }
}

//=============================加减乘除 end=================================